package com.cocklebur;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {

	/*
	 * 函数创建Docket的Bean apiInfo()用来创建该Api的基本信息（这些基本信息会展现在文档页面中）
	 * select()函数返回一个ApiSelectorBuilder实例用来控制哪些接口暴露给Swagger来展现
	 * 本例采用指定扫描的包路径来定义，Swagger会扫描该包下所有Controller定义的API
	 * ，并产生文档内容（除了被@ApiIgnore指定的请求）。
	 */
	@Bean
	public Docket createRestApi() {
		ApiInfo apiInfo  = new ApiInfoBuilder().title("安卓市场系统 APIs").description("安卓市场系统APIs")
        .contact(new Contact("sunyan", "https://github.com/spring256", "ice1938@qq.com"))
        .termsOfServiceUrl("https://gitee.com/ice1938/projects").version("1.0").build();
		Predicate<RequestHandler> requestHandlerSelector = RequestHandlerSelectors
		        .withMethodAnnotation(ResponseBody.class);
		requestHandlerSelector = Predicates.or(requestHandlerSelector,
		        RequestHandlerSelectors.withClassAnnotation(RestController.class));
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).select().apis(requestHandlerSelector).build();
		        //.globalOperationParameters(pars);
	}


}